﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DrawWorkflow
{
    public class VisualLine : VisualObject
    {
        public double X1 { get; set; }
        public double X2 { get; set; }
        public double Y1 { get; set; }
        public double Y2 { get; set; }

        Canvas canvas;

        public override void Draw(Canvas parent)
        {
            this.canvas = parent;
            switch (Status)
            {
                case VisualStatus.Fixed:
                    {
                        if (Common.Distance(X1, X2, Y1, Y2) > 3)
                        {
                            Line line = new Line();
                            line.Stroke = new SolidColorBrush(Colors.Blue);
                            line.StrokeThickness = 4;
                            line.X1 = X1;
                            line.Y1 = Y1;
                            line.X2 = X2;
                            line.Y2 = Y2;
                            line.MouseLeftButtonUp += new MouseButtonEventHandler(line_MouseLeftButtonUp);

                            parent.Children.Add(line);
                        }
                        break;
                    }
                case VisualStatus.Edit:
                    break;
                default:
                    break;
            }
        }


        void line_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            switch (Status)
            {
                case VisualStatus.Fixed:
                    //
                    Line l = sender as Line;
                    l.Stroke = new SolidColorBrush(Colors.Red);

                    Ellipse ellipse = new Ellipse();
                    ellipse.Stroke = new SolidColorBrush(Colors.Blue);
                    ellipse.Height = 7;
                    ellipse.Width = 7;
                    ellipse.SetValue(Canvas.LeftProperty, X1);
                    ellipse.SetValue(Canvas.TopProperty, Y1);
                    canvas.Children.Add(ellipse);

                    Status = VisualStatus.Edit;
                    break;
                case VisualStatus.Edit:
                    Line ll = sender as Line;
                    // canvas.Children.Remove(sender as UIElement);
                    ll.Stroke = new SolidColorBrush(Colors.Blue);



                    Status = VisualStatus.Fixed;
                    break;
                default:
                    break;
            }


        }

    }
}
